Skip to content

Install torch per machine for an app that leaves it out of its lock - #45

Merged
CSSFrancis merged 5 commits into
mainfrom
fix/torch-per-machine
Nov 20, 2026
Merged

CSSFrancis merged 5 commits into
mainfrom
fix/torch-per-machine

Conversation

@CSSFrancis

@CSSFrancis CSSFrancis commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

The bug

An app can leave torch out of uv.lock ([tool.uv] exclude-dependencies = ["torch"], recorded in the lock as [manifest] excludes) so each machine gets the torch build for its GPU. A locked build can't serve every GPU: 2.6.0+cu124 has no kernels for sm_120. Setup decided "this app uses torch" as readLockedTorchVersion(projectDir) !== null, treating "torch not in the lock" the same as "no torch". So an app like this got an exact uv sync: no torch on its first run, a hand-installed torch removed on every upgrade, and a backend that died on import (Autopilot, on a lab PC, 2026-11-16).

Three cases

Michael Spilman's analysis in #30 (item 2) and #44 is the starting point: an app with no torch (Ground Crew) must show no PyTorch step, and the setup state must keep that through every progress line. This PR keeps his behavior for no-torch apps and separates the case that was being mistaken for it. One function, readTorchSetup, decides the case for both setup and the setup window (setupHasTorchStep for the start message's torch flag):

Case How it's detected Setup PyTorch pill
No torch (Ground Crew) anything else, including torch merely absent from the lock exact uv sync, as today no
Locked (SpyDE) the lock pins torch today's two-step (exact sync without torch, then torch==<locked> --torch-backend=auto), unchanged yes
Per machine (Autopilot) the app declares torch (requires-dist) and excludes it from the lock ([manifest] excludes) uv sync --inexact, so an installed torch survives an upgrade and nothing re-downloads; then the app wheels; then a torch check (below) yes

Exact sync stays the rule for the first two cases; only per-machine apps sync inexactly.

In the per-machine case, the check asks the env's Python (python -I):

  • torch loads and has kernels for the GPU: kept.
  • missing: installed with uv pip install --no-config <requirement> --torch-backend=auto, where <requirement> is torch plus any version specifier the app declared.
  • fails to import: --reinstall-package torch.
  • a CUDA GPU the build has no kernels for: --upgrade-package torch, which does nothing when uv has no newer build, so it doesn't loop on every upgrade.
  • the check itself times out or can't run: left alone.

--no-config keeps the app's lock-time [tool.uv] settings out of the torch install (prerelease = "allow" would let a torch release candidate in).

A failed torch install is reported in the overlay, not thrown: the backend starts and can say what it lacks, and the env stamp is removed so the next launch tries again. From a wheelhouse, torch comes from the wheelhouse folder or not at all, with a message saying what to do. installTorchPerMachine works without a torch== pin and takes { reinstall } or { upgrade }, so a "Fix PyTorch" button can replace a torch of the wrong build.

Fixes #44: ENV_SETUP_PROGRESS now spreads prev, so torch and wheelhouse from ENV_SETUP_START survive progress lines and a later failure, using Michael's proposed fix and test. Addresses #30 item 2: the pill decision now comes from the three cases above, so Ground Crew stays pill-free and Autopilot shows it.

Tests

  • npm run typecheck: clean.
  • npm run test:unit: 228 tests, 227 pass, 1 skipped (pre-existing), 0 fail. New tests cover each case:
    • readTorchSetup: none, locked, per machine, and torch excluded but not declared (counts as none)
    • setupHasTorchStep for each case
    • torchInstallArgs, including no pin, reinstall, upgrade and wheelhouse
    • each state the torch check can return
    • keep, install, reinstall, upgrade, failure, still missing after install, and the wheelhouse path in ensureTorchPerMachine
    • stamp dropped on failure
    • progress texts
    • Setup window: a progress line drops torch and wheelhouse, so the PyTorch pill comes back #44's test, and the pill through a progress line and a failure for each case
  • uv run pytest: 138 passed.
  • Real locks: readTorchSetup gives Ground Crew none, SpyDE locked 2.6.0, Autopilot per-machine.
  • End to end on Windows with uv 0.10.11 (TITAN X Pascal), using a throwaway project whose lock excludes torch, through the real resolvePythonEnv:
    1. First run: installed torch 2.9.0+cu129 (2.9 GiB) in 253 s.
    2. Upgrade with a changed lock: torch kept, nothing downloaded, 9.8 s. The old exact sync, as a dry run, "Would uninstall 10 packages … torch==2.9.0+cu129".
    3. Torch install failing behind a dead proxy: reported in the overlay, setup still returned the backend command, stamp removed.
    4. Next launch online: torch reinstalled from cache in 12 s; the launch after that was up to date in 0.0 s.
  • Not run: the wheelhouse path and macOS/Linux (unit tests only), and the Electron overlay itself (its text is unit-tested).

Pascal and other cards older than sm_70. --torch-backend=auto looks only at the driver version, so on this driver it picks cu129, which has no sm_61 kernels; the first GPU operation fails even though torch.cuda.is_available() is True. Setup now chooses the backend before downloading (torchBackend): it reads nvidia-smi --query-gpu=compute_cap, and a card below 7.0 gets cu126; otherwise auto. <APPID>_TORCH_BACKEND overrides it. Checked on the TITAN X: the probe picks cu126, one download installs 2.14.1+cu126 (sm_50 to sm_90), and a 2048x2048 matmul runs on the GPU. Unit tests: 232 passed, 1 skipped.

Merging with #38

A trial merge with #38's head (30500e5) is clean: no conflicting files, and the merged tree typechecks and passes its tests. The two PRs edit neighboring code in pythonEnv.ts (the stamp build, uvEnv, installAppWheel there; the stamp write, setupEnv and new functions here) but never the same lines. Once both are in, the torch check doesn't need #38's withoutPythonRedirects, because python -I already ignores PYTHONPATH and PYTHONHOME.

An app can leave torch out of uv.lock ([tool.uv] exclude-dependencies,
recorded as [manifest] excludes) so each machine gets the build for its
GPU. Setup only handled a locked torch: otherwise it ran an exact
uv sync, which installed no torch on a first run and removed one
installed by hand on every upgrade, and the backend died on import.

Setup now reads the exclusion from the lock and, on every platform,
syncs inexactly (an installed torch survives, nothing re-downloads),
installs the app, then probes the env's torch: kept when it loads and
has kernels for the GPU, installed with --torch-backend=auto when
missing, reinstalled when it does not load, upgraded when it has no
kernels for the GPU (2.6.0+cu124 on sm_120). A failed install is said
in the overlay, not thrown: the backend starts, and the stamp is dropped
so the next launch retries. From a wheelhouse torch comes from the
folder or not at all. installTorchPerMachine works without a pin and
takes reinstall/upgrade for a Fix button. A locked torch is unchanged.

Claude-Session: https://claude.ai/code/session_01DzXsKAUJSM4XYpqqzrcuV5
…rogress

Per machine now needs the app to declare torch (a requires-dist entry)
as well as exclude it from the lock; torch merely absent from the lock
is an app with none, so Ground Crew keeps its exact sync and no pill.
Setup, the two-step and the setup window's PyTorch step all take the
case from readTorchSetup (setupHasTorchStep for the start message).
The requirement parser also missed a bare `{ name = "torch" }` entry,
which is how Autopilot's lock writes it.

A progress line rebuilt the setup state without the torch and
wheelhouse the start had set, so the pill came back for an app with no
torch and an offline install lost its folder line (#44). It now keeps
the rest of the state.

Claude-Session: https://claude.ai/code/session_01DzXsKAUJSM4XYpqqzrcuV5
…oading

uv's --torch-backend=auto reads only the driver version, so a recent driver
on a card older than sm_70 (Pascal, Maxwell) got a cu128+ build with no
kernels for it. Read the compute capability from nvidia-smi first and use
cu126 for such a card; <APPID>_TORCH_BACKEND overrides the choice.
@CSSFrancis
CSSFrancis merged commit 30b49eb into main Nov 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setup window: a progress line drops torch and wheelhouse, so the PyTorch pill comes back

1 participant